# Title     : TODO
# Objective : TODO
# Created by: Administrator
# Created on: 2019/7/24

library(plyr)
library(dplyr)
library(tidyr)
library(tibble)
library(gridExtra)
library(purrr)
library(scales)
library(egg)
library(VennDiagram)
library(optparse)

createWhenNoExist <- function(f){
    ! dir.exists(f) && dir.create(f)
}

option_list <- list(
make_option("--i", default = "AllMet.csv", type = "character", help = "metabolite data file"),
make_option("--g", default = "SampleInfo.csv", type = "character", help = "sample group file")
)
opt <- parse_args(OptionParser(option_list = option_list))

sampleInfo <- read.csv(opt$g, header = T, stringsAsFactors = F) %>%
select(c("SampleID", "ClassNote"))

parent <- paste0("./")
createWhenNoExist(parent)

diffData <- read.table("Sig_Met.txt", header = T, sep = "\t", comment.char = "",
stringsAsFactors = F)
uniData <- diffData %>%
.$Name

pdfFileName <- paste0(parent, "/Venn.pdf")
area1 = length(uniData)
area2 = 0
b <- area1 == 0 & area2 == 0
if (! b) {
    pdf(pdfFileName, width = 8, height = 8)
    crossArea = 0
    draw.pairwise.venn(area1 = area1, area2 = area2, cross.area = crossArea, fill = c("#4040FF", "#FF4040"),
    category = c("Univariate\n", "Multivariate\n"), cat.default.pos = "text",
    cat.cex = 2, cex = c(2, 2, 2), lty = rep("blank", 2), alpha = c(0.5, 0.5),margin=0.1
    )
    dev.off()
}






